package com.mx.tool.form.factory;

import com.intellij.ui.JBColor;
import com.mx.tool.form.window.jy.CronWindow;
import com.mx.tool.form.window.jy.ZzWindow;
import com.mx.tool.form.window.qr.QrCreateWindow;
import com.mx.tool.form.window.qr.QrJxWindow;

import javax.swing.*;

/**
 * @Author: 徐建鹏.
 * @create: 2021-11-10 08:51
 * @Description:
 */
public class QrFactory {

    private final static QrCreateWindow QR_CREATE_WINDOW;
    private final static QrJxWindow QR_JX_WINDOW;

    static {
        QR_CREATE_WINDOW = new QrCreateWindow();
        QR_JX_WINDOW = new QrJxWindow();
    }


    /**
     * 添加监听
     * @param qrCreateButton
     * @param qrJxButton
     * @param qrPanel
     */
    public static void addActionListeners(JButton qrCreateButton, JButton qrJxButton,JPanel qrPanel) {
        JPanel qrCreateJPanel = QR_CREATE_WINDOW.getContent();
        JPanel qrJxJPanel = QR_JX_WINDOW.getContent();
        qrPanel.add("qrCreateJPanel", qrCreateJPanel);
        qrPanel.add("qrJxJPanel", qrJxJPanel);
        qrCreateButton.setForeground(JBColor.GREEN);
        qrCreateButton(qrCreateButton,qrJxButton,qrCreateJPanel,qrJxJPanel);
        qrJxButton(qrCreateButton,qrJxButton,qrCreateJPanel,qrJxJPanel);


    }

    private static void qrCreateButton(JButton qrCreateButton, JButton qrJxButton,  JPanel qrCreateJPanel, JPanel qrJxJPanel) {
        qrCreateButton.addActionListener(e -> {
            qrJxJPanel.setVisible(false);
            qrJxButton.setForeground(JBColor.BLACK);
            qrCreateJPanel.setVisible(true);
            qrCreateButton.setForeground(JBColor.GREEN);
        });
    }

    private static void qrJxButton(JButton qrCreateButton, JButton qrJxButton,  JPanel qrCreateJPanel, JPanel qrJxJPanel) {
        qrJxButton.addActionListener(e -> {
            qrCreateJPanel.setVisible(false);
            qrCreateButton.setForeground(JBColor.BLACK);
            qrJxJPanel.setVisible(true);
            qrJxButton.setForeground(JBColor.GREEN);

        });
    }

}
